﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class CTHDBanSiDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertCTHDBS(CTHDBanSiDTO CTHDBanSi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", CTHDBanSi.MaMH);
            par[1] = new SqlParameter("@MaHDBS", CTHDBanSi.MaHDBS);
            par[2] = new SqlParameter("@DonGia", CTHDBanSi.DonGia);
            par[3] = new SqlParameter("@SoLuong", CTHDBanSi.SoLuong);
            par[4] = new SqlParameter("@ChietKhau", CTHDBanSi.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", CTHDBanSi.ThanhTien);
            try
            {
                helper.InsertQuery("sp_Insert_CTHDBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTHDBS(CTHDBanSiDTO CTHDBanSi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", CTHDBanSi.MaMH);
            par[1] = new SqlParameter("@MaHDBS", CTHDBanSi.MaHDBS);
            par[2] = new SqlParameter("@DonGia", CTHDBanSi.DonGia);
            par[3] = new SqlParameter("@SoLuong", CTHDBanSi.SoLuong);
            par[4] = new SqlParameter("@ChietKhau", CTHDBanSi.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", CTHDBanSi.ThanhTien);
            try
            {
                helper.UpdateQuery("sp_Update_CTHDBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTHDBS(string maMH, string maHDBS)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maMH", maMH);
            par[1] = new SqlParameter("@maHDBL", maHDBS);
            try
            {
                helper.DeleteQuery("sp_Delete_CTHDBanSi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTHDBanSi()
        {
            helper = new Helper();
            DataSet ds_CTHDBS = helper.SelectQuery("sp_LayDS_CTHDBanSi");
            return ds_CTHDBS;
        }
        #endregion
    }
}